#set($layout="layout/index-main.html")
#set($pageTitle="用户管理")
<link rel="stylesheet" href="${basepath}/js/ligerUI/css/ligerui-all.css" type="text/css">
<div id="user_manager_div">

</div>
<script type="text/javascript" src="$!{basepath}/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="$!{basepath}/js/ligerUI/ligerui.min.js"></script>
<script type="text/javascript">
var listgrid;
var statusData = [{ status: 0, text: 'Disable'},{ status: 1, text: 'Enable' }];
var sexData = [{ sex: 0, text: 'Female'},{ sex: 1, text: 'Male' }];
/* 工具条 */
function listToolbar()
{
    var items = [];
    items.push({ text: 'Add', click: grid_add, img: "${basepath}/js/ligerUI/images/icon/page_add.png" });
    items.push({ text: 'Modify', click: grid_edit, img: "${basepath}/js/ligerUI/images/icon/edit.gif" });
    return { items: items };
    function grid_add()
    {
    	alert(" open the add windows !");
    }
    function grid_edit()
    {
        var selected = listgrid.getSelected();
        if (!selected) { $.ligerDialog.warn( '请选择行'); return; }
        
    }
}
$(function(){
	listgrid = $("#user_manager_div").ligerGrid({
	    columns: [
		{ display: '', name: 'id',hide:1 },         
	    { display: '登录名', name: 'userName', width: '12%'},
	    { display: '昵　称', name: 'nickName', width: '12%',editor: { type: 'text' }},
	    { display: '联系电话', name: 'telNum', width: '12%',editor: { type: 'text' }},
	    { display: '电子邮件', name: 'email', width: '12%',editor: { type: 'text' }},
	    { display: '性　别', name: 'sex', width: '5%' ,type:'String',
	    	render:function(item)
			{
				return sexData[item.sex].text;
			},
			editor: {type:'select',data:sexData,valueColumnName: 'sex'}
	    },
	    { display: '状态', name: 'status', width: '5%',type: 'String',
	    	render: function (item)
                    {
                        return statusData[item.status].text;
                    },
	        editor: { type: 'select', data: statusData, valueColumnName: 'status' }
        },
	    { display: '操作', isSort: false, width: '15%', render: function (rowdata, rowindex, value)
            {
                var h = "";
                if (!rowdata._editing)
                {
                    h += "<a href='javascript:beginEdit(" + rowindex + ")'>Modify</a> ";
                    h += "<a href='javascript:viewInfo(" + rowindex + ")'>Detail</a> "; 
                }
                else
                {
                    h += "<a href='javascript:endEdit(" + rowindex + ")'>Submit</a> ";
                    h += "<a href='javascript:cancelEdit(" + rowindex + ")'>Cancel</a> "; 
                }
                return h;
            }
         }
	    ],width:'80%',
	    pageParmName: 'pageno',
	    pagesizeParmName:'pagesize',
	    sortnameParmName:'sortname',
	    sortorderParmName:'sortorder', 
	    root:'result',
	    record:'totalsize',
	    page: ${pageno},
	    pageSize: ${pagesize},
	    pageSizeOptions: [${pagesize}, 30, 50, 100],
	    url: '${basepath}/user/page.htm',
	    onAfterShowData: function (grid)
	    {
	        if ($.fn.ligerCheckBox)
	            $(".l-grid-body input:checkbox,.l-grid-hd-cell input:checkbox", grid).ligerCheckBox({ css: { marginTop: 3} })
	    },
	    toolbar: listToolbar(),
		enabledEdit: true,
		clickToEdit:false, 
		isScroll: false
	});
});

/* 编辑 */
function beginEdit(rowid) { 
    listgrid.beginEdit(rowid);
}
/* 取消 */
function cancelEdit(rowid) { 
    listgrid.cancelEdit(rowid);
}
/* 编辑结束,提交 */
function endEdit(rowid)
{
    listgrid.endEdit(rowid);
    var currow = listgrid.rows[rowid];
    var nickName = currow.nickName;
    var telNum = currow.telNum; 
    var email = currow.email; 
    var sex = currow.sex; 
    var status = currow.status; 
    var id = currow.id;
 	$.post("${basepath}/user/modify.htm",
    	{
	 		"nickName":nickName,
	 		 "telNum":telNum,
	 		 "sex":sex,
	 		 "status":status,
	 		 "email":email,
	 		 "id":id,
	 		 "_method":"put"
 		 },
    	function(data){
    		if(data == 1){
    			
    		}else{
    			listgrid.cancelEdit(rowid);
    			$.ligerDialog.error('更新用户组失败,请稍候重试!');
    		}
    	}
    );
}
</script>
